package cn.chinasyq.photoquan.photo.window;

import android.app.Activity;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.photo.bean.ExinfoEntry;

/**
 * Created by 一搏 on 2015/12/10.
 */
public class InfoWindows extends PopupWindow implements View.OnClickListener {

    Activity mContext;
    private int mWidth;
    private int mHeight;
    private int statusBarHeight;
    private ExinfoEntry exinfoEntry;
    private Button ibtn_close;
    private TextView tv_size;
    private TextView tv_make;
    private TextView tv_device;
    private TextView tv_date_time;
    private TextView tv_exposure_time;
    private TextView tv_focal_length;
    private TextView tv_iso;
    private TextView tv_flash;
    private TextView tv_white_balance;
    private TextView tv_aperture_value;

    public InfoWindows(Activity context) {
        super(context);
        mContext = context;
        init();
    }

    private void init() {
        Rect frame = new Rect();
        mContext.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        statusBarHeight = frame.top;
        DisplayMetrics metrics = new DisplayMetrics();
        mContext.getWindowManager().getDefaultDisplay()
                .getMetrics(metrics);
        mWidth = metrics.widthPixels;
        mHeight = metrics.heightPixels-statusBarHeight;

        setWidth(mWidth);
        setHeight(mHeight);
    }


    public void showMoreWindow(View anchor) {
        final FrameLayout layout = (FrameLayout) LayoutInflater.from(mContext).inflate(R.layout.layout_photo_info_windows, null);
        setContentView(layout);
        tv_size = (TextView) layout.findViewById(R.id.tv_size);
        tv_make = (TextView) layout.findViewById(R.id.tv_make);
        tv_device = (TextView) layout.findViewById(R.id.tv_device);
        tv_date_time = (TextView) layout.findViewById(R.id.tv_date_time);
        tv_exposure_time = (TextView) layout.findViewById(R.id.tv_exposure_time);
        tv_focal_length = (TextView) layout.findViewById(R.id.tv_focal_length);
        tv_iso = (TextView) layout.findViewById(R.id.tv_iso);
        tv_white_balance = (TextView) layout.findViewById(R.id.tv_white_balance);
        tv_flash = (TextView) layout.findViewById(R.id.tv_flash);
        tv_aperture_value = (TextView) layout.findViewById(R.id.tv_aperture_value);
        ibtn_close = (Button) layout.findViewById(R.id.ibtn_close);
        ibtn_close.setOnClickListener(this);
        if (exinfoEntry != null) {
            tv_size.setText("尺寸："+exinfoEntry.getSize());
            tv_make.setText("制造商："+exinfoEntry.getMake());
            tv_device.setText("型号："+exinfoEntry.getDevice());
            tv_date_time.setText("时间："+exinfoEntry.getDate_time());
            tv_exposure_time.setText("快门："+exinfoEntry.getExposure_time());
            tv_focal_length.setText("焦距："+exinfoEntry.getFocal_length());
            tv_iso.setText("ISO："+exinfoEntry.getIso());
            tv_white_balance.setText("白平衡："+exinfoEntry.getWhite_balance());
            tv_flash.setText("闪光灯："+exinfoEntry.getFlash());
            tv_aperture_value.setText("光圈："+exinfoEntry.getAperture_value());
        } else {
            tv_size.setText("");
            tv_make.setText("");
            tv_device.setText("");
            tv_date_time.setText("");
            tv_exposure_time.setText("");
            tv_focal_length.setText("");
            tv_iso.setText("");
            tv_white_balance.setText("");
            tv_flash.setText("");
            tv_aperture_value.setText("");
        }
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setBackgroundDrawable(null);
        setOutsideTouchable(true);
        setFocusable(true);
        showAtLocation(anchor, Gravity.BOTTOM, 0, statusBarHeight);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ibtn_close:
                dismiss();
                break;
            default:
                break;
        }
    }

    public ExinfoEntry getExinfoEntry() {
        return exinfoEntry;
    }

    public void setExinfoEntry(ExinfoEntry exinfoEntry) {
        this.exinfoEntry = exinfoEntry;
    }

}

